import { _HttpClient } from '@delon/theme';
import { Observable } from 'rxjs';
import { ComprehensiveScoreDTO } from 'src/app/project/model/icm/icm-student-academic/comprehensive-evaluation/comprehensive-evaluation.dto';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root',
})
export class ComprehensiveScoreService {
  private static URL = '/api/icm-comprehensive-score';

  constructor(private http: _HttpClient) {}

  /**
   * 模糊查询学生综合测评
   *
   * @param academyName 所属学院name
   * @param professionName 所属专业name
   * @param className 所属班级name
   * @param classId 所属班级id
   * @param studentName 学生name
   * @param studentId 学生id
   * @param year 所属年度
   * @param compAssessProcessStatus 流程状态
   * @param studentCode 学生code
   */
  search(
    academyName?: string,
    professionName?: string,
    className?: string,
    classId?: string,
    studentName?: string,
    studentId?: string,
    year?: string,
    compAssessProcessStatus?: string,
    studentCode?: string,
  ): Observable<Array<ComprehensiveScoreDTO>> {
    const params = {};
    Object.assign(
      params,
      academyName ? { academyName } : {},
      professionName ? { professionName } : {},
      className ? { className } : {},
      classId ? { classId } : {},
      studentName ? { studentName } : {},
      studentId ? { studentId } : {},
      year ? { year } : {},
      compAssessProcessStatus ? { compAssessProcessStatus } : {},
      studentCode ? { studentCode } : {},
    );
    return this.http.get<Array<ComprehensiveScoreDTO>>(ComprehensiveScoreService.URL, params);
  }

  /**
   * 根据id查找学生综合测评
   * @param id 学生综合测评id
   */
  findById(id: string): Observable<ComprehensiveScoreDTO> {
    return this.http.get<ComprehensiveScoreDTO>(`${ComprehensiveScoreService.URL}/${id}`);
  }

  /**
   * 新建学生综合测评
   * @param comprehensiveScoreDTO 综合测评
   */
  create(comprehensiveScoreDTO: ComprehensiveScoreDTO): Observable<ComprehensiveScoreDTO> {
    return this.http.post<ComprehensiveScoreDTO>(ComprehensiveScoreService.URL, comprehensiveScoreDTO);
  }

  /**
   * 提交学生综合测评
   * @param id 学生综合测评id
   * @param comprehensiveScoreDTO 学生综合测评
   */
  complete(id: string, comprehensiveScoreDTO: ComprehensiveScoreDTO): Observable<ComprehensiveScoreDTO> {
    return this.http.put<ComprehensiveScoreDTO>(`${ComprehensiveScoreService.URL}/${id}`, comprehensiveScoreDTO);
  }

  /**
   * 查找所有学生综合测评
   * @param studentId 学生id
   * @param compAssessProcessStatus 流程状态
   */
  findAll(studentId: string, compAssessProcessStatus: string): Observable<ComprehensiveScoreDTO> {
    const params = {};
    Object.assign(params, studentId ? { studentId } : {}, compAssessProcessStatus ? { compAssessProcessStatus } : {});
    return this.http.get<ComprehensiveScoreDTO>(`${ComprehensiveScoreService.URL}/findAll`, params);
  }
}
